using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using SQLDAL;
using System.Web.Mail;

/// <summary>
/// Summary description for CommonUse
/// All method will be used by all class commonly
/// </summary>
public class CommonUse
{
    public CommonUse()
	{
		
	}

    // Fill data to drop down list control
     public void LoadDataToDropDownList(DropDownList dropDownList, CommandType cmdType, string cmdText, string tableName,
                                    string displayMember, string valueMember)
    {
        
        DataSet ds = SQLHelper.GetDataSetUsingSP(cmdType, cmdText, tableName);
        dropDownList.DataSource = ds.Tables[tableName];
        dropDownList.DataTextField = displayMember;
        dropDownList.DataValueField = valueMember;
    }

    public bool SendMail(string emailTo, string codeID)
    {
        bool send = true;
        string error = null;
        string body = "Thank you for your booking at our Restaurant.<br/>Your codeID is: <strong>" + codeID + "</strong><br/>." +
                "Please keep this code in case you want to cancel your booking/order. <br/>"
            + "TUNGA Restaurant";
        string subject = "ACCEPT YOUR BOOKING AT TUNGA RESTAURANT";
        try
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.To = emailTo;
            mailMsg.Subject = subject;
            
            mailMsg.Body = body;
            mailMsg.BodyFormat = MailFormat.Html;
            mailMsg.Priority = MailPriority.High;
            mailMsg.From = "pvtphuong@gmail.com";
            SmtpMail.SmtpServer = "pvtphuong@gmail.com";
            SmtpMail.Send(mailMsg);
        }
        catch (Exception ex)
        {
            send = false;
            error = ex.Message;
        }
        return send;
    }
}
